# -*- coding:utf-8 -*-
# --author： jingfeng 
# time: 2019/5/31


from PIL import Image

image2 = Image.open('image2.png')
image1 = Image.open('image1.png')

def get_distance(image1, image2):
    '''
      拿到滑动验证码需要移动的距离
      :param image1:没有缺口的图片对象
      :param image2:带缺口的图片对象
      :return:需要移动的距离
      (360, 140)
      '''
    # print('size', image1.size)



    a = 0
    threshold =70
    left = 57
    for i in range(0, image1.size[0]):
        for j in range(image1.size[1]):
            rgb1 = image1.load()[i, j]
            rgb2 = image2.load()[i, j]
            res1 = abs(rgb1[0] - rgb2[0])
            res2 = abs(rgb1[1] - rgb2[1])
            res3 = abs(rgb1[2] - rgb2[2])
            if not (res1 < threshold and res2 < threshold and res3 < threshold):
                return i


res = get_distance(image1,image2)
print(res)